module.exports = {

}

const YAML = require('yamljs');
const path_js = require('path');
const YamlPath = path_js.join(rootpath,"config.yml");
const CustomYamlPath = path_js.join(rootpath, "config.custom.yml");
//全局保存配置信息
global.config = JSON.parse(JSON.stringify(YAML.load(YamlPath)));
try{
  cover(global.config, JSON.parse(JSON.stringify(YAML.load(CustomYamlPath))))
}catch (e){
  console.log("覆盖失败:" + e.message)
}
//添加管理员账号
global.admin = new Set();
for(let i in config.client.admin){
  admin.add(config.client.admin[i]);
}

/** 使用新的字典覆盖老的字典 */
function cover(dic_old, dic_new){
  for(const item in dic_new){
    //老的字典里存在该键值
    if(item in dic_old){
      //两者都是字典,递归调用
      if(support.isDictionary(dic_new[item]) && support.isDictionary(dic_old[item])){
        cover(dic_old[item], dic_new[item])
        //两者都是数组,直接插入末尾
      } else {
        dic_old[item] = dic_new[item];
      }
    }

  }
}
